package cn.yunhe.action;

import cn.yunhe.pojo.Member;
import cn.yunhe.service.MemberService;
import cn.yunhe.util.BaseAction;
import com.opensymphony.xwork2.ModelDriven;

public class MemberAction extends BaseAction implements ModelDriven {
    private Member member;
    private String tag;

    MemberService memberService=new MemberService();


    /**
     * 注册
     * @return
     */
    public String register(){
        /*singleMember(member);*/
        member.setMstate(1);
        member.setMflag(1);
        boolean flag=memberService.register(member);
        if (flag){
            tag="login";
        }else {
            tag="register";
        }
        return "target";
    }

    public String login(){
        singleMember(member);
        Member member1=memberService.login(member);
        if (member1!=null){
            tag="list";
        }else {
            tag="login";
        }
        return "target";
    }

    public Member getMember() {
        return member;
    }

    public void setMember(Member member) {
        this.member = member;
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    @Override
    public Member getModel() {
        if (member==null)
            member=new Member();
        return member;
    }


    public void singleMember(Member member){
        System.out.print(member.getMid()+"\t");
        System.out.print(member.getMaccount()+"\t");
        System.out.print(member.getMpwd()+"\t");
        System.out.print(member.getMphone()+"\t");
        System.out.print(member.getMname()+"\t");
        System.out.print(member.getMstate()+"\t");
        System.out.print(member.getMflag()+"\t");
        System.out.println();
    }
}
